package com.situ.mall.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.situ.mall.mapper.AdminMapper;
import com.situ.mall.pojo.Admin;
import com.situ.mall.pojo.query.AdminQuery;
import com.situ.mall.pojo.vo.ProductCountVo;
import com.situ.mall.service.IAdminService;
import com.situ.mall.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class AdminService implements IAdminService {
    @Autowired
    private AdminMapper adminMapper;
    @Override
    public List<Admin> selectAll() {
        return adminMapper.selectAll();
    }

    @Override
    public PageResult<Admin> selectByPage(AdminQuery adminQuery) {
        PageHelper.startPage(adminQuery.getPage(),adminQuery.getLimit());
        List<Admin> list = adminMapper.selectByPage(adminQuery);
        PageInfo pageInfo = new PageInfo(list);
        int totalCount = (int) pageInfo.getTotal();
        return new PageResult<>(0,"",totalCount,list);
    }

    @Override
    public void add(Admin admin) {
        adminMapper.add(admin);
    }

    @Override
    public void deleteById(Integer id) {
        adminMapper.deleteById(id);
    }

    @Override
    public void deleteAll(Integer[] ids) {
        adminMapper.deleteAll(ids);
    }

    @Override
    public List<ProductCountVo> selectCount() {
        List<ProductCountVo> list = adminMapper.selectCount();
        return list;
    }

    @Override
    public Admin login(String name, String password) {
        return adminMapper.login(name,password);
    }

    @Override
    public Admin selectById(Integer id) {
        return adminMapper.selectById(id);
    }

    @Override
    public void update(Admin admin) {
        adminMapper.update(admin);
    }
}
